package easy;

import util.PrintUtils;

public class Solution_566 {

    public int[][] matrixReshape(int[][] mat, int r, int c) {
        int num = mat.length * mat[0].length;
        if (num != r*c) {
            return mat;
        }

        int index = 0;
        int[][] res = new int[r][c];
        for (int[] ints : mat) {
            for (int item : ints) {
                int j = index/c;
                int k = index%c;
                res[j][k] = item;
                index++;
            }
        }
        return res;
    }

    public static void main(String[] args) {
        Solution_566 model = new Solution_566();
        int[][] ints = model.matrixReshape(new int[][]{{1, 2}, {3, 4}}, 4, 1);
        for (int[] anInt : ints) {
            PrintUtils.arrayInt(anInt);
        }
    }
}
